#include "FileManager.h"
#include "MyLog.h"
#include "MyUtils.h"

FileInfo* FileInfo_open(const char *filePath){
    FileInfo *info = (FileInfo *)malloc(sizeof(FileInfo));
    splicString(info->path, sizeof(info->size), 1, filePath);

    info->handle = fopen(info->path, "rb");
    if(info->handle == NULL){
        MY_LOGE("file %s open failed!", info->path);
        return 0;
    }

	// 获取文件大小
    fseek(info->handle, 0, SEEK_END);
    info->size =ftell(info->handle);
    fseek(info->handle, 0, SEEK_SET); //文件指针归零
    info->remove = FileInfo_remove;
    info->readLine = FileInfo_readLine;

    return info;
}


int FileInfo_remove( FileInfo *thiz){
    return remove(thiz->path);
}
int FileInfo_destory(FileInfo *thiz){

    if(thiz){
        if(thiz->handle) { fclose(thiz->handle); };
        free(thiz);
    }
    return 0;
}


int FileInfo_readLine(FileInfo *file, char *buff, int size){
    MY_LOGD("%d",size);
    while(fgets(buff,size, file->handle) != NULL){
        MY_LOGD("%s",buff);
    }
    return 0;
}

